<template>
  <div>
    <el-button type="primary" @click="rowNew">新增</el-button>
    <el-button type="success" >导出</el-button>
    <el-button type="success" >审核</el-button>
    <el-button type="danger" >审核不通过</el-button>
    <el-button type="warning" >取消审核</el-button>
    <el-button type="primary" >转发</el-button>
    <el-button type="success" >处理</el-button>
    <!--表格内容-->
    <el-table
      ref="list"
      :data="tableData"
      style="width: 100%;margin-top: 1vw;"
      border
      stripe
      highlight-current-row
      :default-sort="{prop: 'date', order: 'descending'}"
      @row-click="handleRowClick"
      @select-all="handleCheckedAllAndCheckedNone"
      @select="handleCheckedAllAndCheckedNone">

      <el-table-column property="name" label="提交人工号" width="100" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="address" label="事件所在" width="50"></el-table-column>
      <el-table-column property="date" label="提交人姓名" width="120" sortable :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 5px">{{scope.row.date}}</span>
        </template>
      </el-table-column>
      <el-table-column property="date" label="质管科处" width="120" sortable :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 5px">{{scope.row.date}}</span>
        </template>
      </el-table-column>
      <el-table-column property="date" label="提交状态" width="120" sortable :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 5px">{{scope.row.date}}</span>
        </template>
      </el-table-column>
      <el-table-column property="name" label="质管科处" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="填报时间" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="患者卡号" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="卡号" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="患者姓名" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="性别" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="出生日期" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="体重(KG)" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="联系电话" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="家族史" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="过敏史" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="不良反应" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="不良反应" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="发生时间" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="临床诊断" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="此时发生" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" width="130" align="center">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit-outline" type="primary" title="编辑" size="small"
            @click="rowEdit(scope.$index, scope.row)"></el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="删除" size="small"
            @click="rowDel(scope.$index, scope.row, $event);"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      :page-sizes="[10, 20, 30, 40]"
      :page-size="10"
      :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--编辑-弹出层-->
    <el-dialog
      title="新增"
      :visible.sync="isShowEditDialog"
      width="1000px"
      @close="dialogClose">
      <el-form
        ref="editForm"
        :model="formFileds"
        label-width="55px"
        :rules="rules">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="患者资料" prop="name" label-width="120px">
              <el-checkbox-group v-model="checkList">
                <el-checkbox label="就诊卡号"></el-checkbox>
                <el-checkbox label="处方号"></el-checkbox>
                <el-checkbox label="健康号"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-input v-model="formFileds.col2" style="width: 300px"></el-input>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名" prop="address" label-width="120px">
              <el-input v-model="formFileds.col3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出生日期" prop="address" label-width="120px">
<!--              <el-input v-model="formFileds.col4"></el-input>-->
              <el-date-picker v-model="formFileds.col4" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别" prop="address" label-width="120px">
              <el-input v-model="formFileds.col5"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="体重" prop="address" label-width="120px">
              <el-input v-model="formFileds.col6"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系电话" prop="address" label-width="120px">
              <el-input v-model="formFileds.col7"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="过敏史" prop="address" label-width="120px">
              <el-input v-model="formFileds.col8"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="家族史" prop="address" label-width="120px">
              <el-input v-model="formFileds.col9"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="临床诊断" prop="address" label-width="120px">
            <el-input v-model="formFileds.col10"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="可疑用药" prop="address" label-width="120px">
            <el-input v-model="formFileds.col11"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件发生场所" prop="address" label-width="120px">
            <el-checkbox-group v-model="checkList">
              <el-checkbox label="急诊"></el-checkbox>
              <el-checkbox label="门诊"></el-checkbox>
              <el-checkbox label="病区"></el-checkbox>
              <el-checkbox label="医技部门"></el-checkbox>
              <el-checkbox label="其他"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="不良反应" prop="address" label-width="120px">
            <el-checkbox-group v-model="formFileds.col13">
              <el-checkbox label="过敏反应"></el-checkbox>
              <el-checkbox label="胃肠道反应"></el-checkbox>
              <el-checkbox label="心血管反应"></el-checkbox>
              <el-checkbox label="呼吸系统反应"></el-checkbox>
              <el-checkbox label="神经、精神系统反应"></el-checkbox>
              <el-checkbox label="骨骼运动系统反应"></el-checkbox>
              <el-checkbox label="血液系统反应"></el-checkbox>
              <el-checkbox label="内分泌系统反应"></el-checkbox>
            </el-checkbox-group>
            <el-input type="textarea" v-model="formFileds.col14"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
            <el-col :span="12">
              <el-form-item label="发生时间" prop="address" label-width="120px">
<!--                <el-input v-model="formFileds.col15"></el-input>-->
                <el-date-picker v-model="formFileds.col15" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="上报科室" prop="address" label-width="120px">
                <el-input v-model="formFileds.col16"></el-input>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row>
          <el-form-item label="不良反应事件上报过程简述" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col17"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="此事发生或发现人员" prop="address" label-width="150px">
            <el-checkbox-group v-model="checkList">
              <el-checkbox label="医生"></el-checkbox>
              <el-checkbox label="护士"></el-checkbox>
              <el-checkbox label="医技"></el-checkbox>
              <el-checkbox label="行政"></el-checkbox>
              <el-checkbox label="工人"></el-checkbox>
              <el-checkbox label="其他"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="导致事件的可能原因" prop="address" label-width="150px">
            <el-checkbox-group v-model="checkList">
              <el-checkbox label="个人原因"></el-checkbox>
              <el-checkbox label="设备设施原因"></el-checkbox>
              <el-checkbox label="耗材药品原因"></el-checkbox>
              <el-checkbox label="系统流程原因"></el-checkbox>
              <el-checkbox label="工作环境原因"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="附件" prop="address" label-width="120px">

          </el-form-item>
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="handleEdit(formFileds.id)" class="pull-right margin-l-25">确定</el-button>
          <el-button @click="isShowEditDialog = false;" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "Table",
    data() {
      return {
        checkList:[],
        formFileds: {
          date: '',
          name: '',
          address: '',
          id: '',
          col1:undefined,
          col2:undefined,
          col3:undefined,
          col4:undefined,
          col5:undefined,
          col6:undefined,
          col7:undefined,
          col8:undefined,
          col9:undefined,
          col10:undefined,
          col11:undefined,
          col12:undefined,
          col13:undefined,
          col14:undefined,
          col15:undefined,
          col16:undefined,
          col17:undefined,
          col18:undefined,
          col19:undefined,
          col20:undefined,
          col21:undefined,
          col22:undefined,
          col23:undefined,
          col24:undefined,
          col25:undefined,
          col26:undefined,
          col27:undefined,
          col28:undefined,
          col29:undefined,
          col30:undefined,
          col31:undefined,
          col32:undefined,
          col33:undefined,
          col34:undefined,
          col35:undefined,
          col36:undefined,
          col37:undefined,
        },
        rules: {
          name: [
            {required: true, message: '姓名不能为空', trigger: 'blur, change'}
          ],
          address: [
            {required: true, message: '地址不能为空', trigger: 'blur, change'}
          ]
        },
        tableData: [{
          id: 0,
          date: '2016-05-02',
          name: '王小虎',
          address: '男'
        }, {
          id: 1,
          date: '2016-05-04',
          name: '王小虎',
          address: '男'
        }, {
          id: 2,
          date: '2016-05-01',
          name: '王小虎',
          address: '男'
        }, {
          id: 3,
          date: '2016-05-03',
          name: '王小虎',
          address: '男'
        }],
        isShowEditDialog: false
      }
    },
    methods: {
      rowNew(){
        this.resetForm();
        this.isShowEditDialog = true;
      },
      handleRowClick(row, event, column) {
        // 仅选中当前行
        this.setCurRowChecked(row);
      },
      handleCheckedAllAndCheckedNone(selection) {
        // 当前选中仅一行时操作-（当前表格行高亮）
        1 != selection.length && this.$refs.list.setCurrentRow();
      },
      dialogClose() {
        // 清空编辑表单
        this.$refs.editForm.resetFields();
      },
      //清空表单信息
      resetForm(){
        this.formFileds={
          date: '',
          name: '',
          address: '',
          id: '',
          col1:undefined,
          col2:undefined,
          col3:undefined,
          col4:undefined,
          col5:undefined,
          col6:undefined,
          col7:undefined,
          col8:undefined,
          col9:undefined,
          col10:undefined,
          col11:undefined,
          col12:undefined,
          col13:undefined,
          col14:undefined,
          col15:undefined,
          col16:undefined,
          col17:undefined,
          col18:undefined,
          col19:undefined,
          col20:undefined,
          col21:undefined,
          col22:undefined,
          col23:undefined,
          col24:undefined,
          col25:undefined,
          col26:undefined,
          col27:undefined,
          col28:undefined,
          col29:undefined,
          col30:undefined,
          col31:undefined,
          col32:undefined,
          col33:undefined,
          col34:undefined,
          col35:undefined,
          col36:undefined,
          col37:undefined,
        }
      },
      rowEdit(index, row) {
        this.setCurRowChecked(row);
        // 给编辑弹出层赋值
        // ***这里需要注意的是：因为加了排序 所以tableData的顺序和实际显示的行顺序不一样
        for (let key in this.formFileds) {
          this.formFileds[key] = row[key];
        }
        this.isShowEditDialog = true;
      },
      handleEdit(id) {
        this.$refs.editForm.validate(isValid => {
          if (!isValid) return;
          // 保存编辑后的数据
          Object.assign(this.tableData[id], this.formFileds);
          this.isShowEditDialog = false;
          // 考虑到可能编辑了日期-需要重新排序
          // ***注意：手动排序传参和表格的default-sort属性格式不太一样
          this.$refs.list.sort('date', 'descending');
          this.$message.success('编辑成功');
        });
      },
      rowDel(index, row, event) {
        // 让当前删除按钮失焦
        event.target.blur();
        this.$confirm('确定要删除当前行吗？', '删除', {
          comfirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(() => {
          this.tableData.splice(row.id, 1);
          this.$message.success('删除成功');
          return false;
        });
      },
      // 选中当前行-当前行的复选框被勾选
      setCurRowChecked(row) {
        this.$refs.list.clearSelection();
        this.$refs.list.toggleRowSelection(row);
      }
    }
  }
</script>

<style scoped lang="less">
.el-form {
  padding: 0 10px;
}
.el-date-editor {
  width: 100% !important;
}
</style>
